<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="robot" content="index,follow">
<title>Module nfe - Non-deterministic finite automata expression - Forth Foundation Library</title>
</head>
<body>
<h2>nfe - Non-deterministic finite automata expression</h2>
<h3>Module Description</h3>
<p>The nfe module implements an expression in a non-deterministic finite
automata. An expression is a concatenation, repetition or alteration of
non-deterministic finite automata states [nfs]. An not yet fully built
expression consists of two cells on the stack: a list with the non resolved
out states and a list of [nfs] states.<br>
The code is based on the Thompson NFA algorithm published by Russ Cox.
</p>
<h3>Module Words</h3>
<dl>
</dl>
<h4>Expression structure</h4>
<dl>
<dt><a name="word1"><b>nfe%</b>	( -- n )</dt>
<dd>Get the required space for a nfe expression</dd>
</dl>
<h4>Expression creation, initialisation and cleanup</h4>
<dl>
<dt><a name="word2"><b>nfe-init</b>	( nfe -- )</dt>
<dd>Initialise the expression</dd>
<dt><a name="word3"><b>nfe+free-expression</b>	( nfe -- )</dt>
<dd>Free all states in the [sub]expression [recursive]</dd>
<dt><a name="word4"><b>nfe-(free)</b>	( nfe -- )</dt>
<dd>Free the internal, private variables from the heap</dd>
<dt><a name="word5"><b>nfe-create</b>	( "&lt;spaces&gt;name" -- ; -- nfe )</dt>
<dd>Create a named expression in the dictionary</dd>
<dt><a name="word6"><b>nfe-new</b>	( -- nfe )</dt>
<dd>Create a new expression on the heap</dd>
<dt><a name="word7"><b>nfe-free</b>	( nfe -- )</dt>
<dd>Free the expression from the heap</dd>
</dl>
<h4>Member words</h4>
<dl>
<dt><a name="word8"><b>nfe-visit++</b>	( nfe -- n )</dt>
<dd>Increment the visit number in the expression, return the visit number</dd>
<dt><a name="word9"><b>nfe-level+@</b>	( nfe -- n )</dt>
<dd>Increment and return the paren level</dd>
<dt><a name="word10"><b>nfe-visit@</b>	( nfe -- n )</dt>
<dd>Get the current visit number</dd>
<dt><a name="word11"><b>nfe-expression@</b>	( nfe -- a-addr )</dt>
<dd>Get the list of states in the expression or nil</dd>
<dt><a name="word12"><b>nfe-states@</b>	( nfe -- n )</dt>
<dd>Get the number of states in the expression</dd>
<dt><a name="word13"><b>nfe-parens@</b>	( nfe -- n )</dt>
<dd>Get the number of parens in the expression</dd>
</dl>
<h4>Expression building words</h4>
<dl>
<dt><a name="word14"><b>nfe-clear</b>	( nfe -- )</dt>
<dd>Clear the expression</dd>
<dt><a name="word15"><b>nfe-single</b>	( x n nfe -- nfs1 nfs2 )</dt>
<dd>Start an expression, nfs2 nfs1, with a single new state nfs1 with data x and type n</dd>
<dt><a name="word16"><b>nfe-concat</b>	( nfs1 nfs2 nfs3 nfs4 nfe -- nfs5 nfs6 )</dt>
<dd>Concat the two expressions, return the outs nfs5 and start nfs6</dd>
<dt><a name="word17"><b>nfe-paren</b>	( nfs1 nfs2 n nfe -- nfs3 nfs4 )</dt>
<dd>Paren the expression with level n, return the new outs nf3 and start nfs4</dd>
<dt><a name="word18"><b>nfe-alternation</b>	( nfs1 nfs2 nfs3 nfs4 nfe -- nfs5 nfs6 )</dt>
<dd>Make an alternation [|] of two expressions, return the new outs nfs5 and start nfs6</dd>
<dt><a name="word19"><b>nfe-zero-or-one</b>	( nfs1 nfs2 nfe -- nfs3 nfs4 )</dt>
<dd>Repeat the expression one or zero [?] times, return the new start outs nfs3 and start nfs4</dd>
<dt><a name="word20"><b>nfe-zero-or-more</b>	( nfs1 nfs2 nfe -- nfs3 nfs4 )</dt>
<dd>Repeat the expression zero or more [*] times, return the new outs nfs3 and start nfs4</dd>
<dt><a name="word21"><b>nfe-one-or-more</b>	( nfs1 nfs2 nfe -- nfs3 nfs4 )</dt>
<dd>Repeat the expression one or more [+] times, return the new outs nfs3 and start nfs4</dd>
<dt><a name="word22"><b>nfe-close</b>	( nfs1 nfs2 nfe -- nfs3 )</dt>
<dd>Close the expression by adding the match state, return the start nfs3</dd>
</dl>
<h4>Matching words</h4>
<dl>
<dt><a name="word23"><b>nfe-match?</b>	( c-addr u flag nfe -- flag )</dt>
<dd>Match a string c-addr u, with the flag indicating case insensitive match, return the match result</dd>
<dt><a name="word24"><b>nfe-search</b>	( c-addr u flag nfe -- n )</dt>
<dd>Search in the string c-addr u for a match, with the flag indicating case insensitive match, return the first offset for a match, or -1 for no match</dd>
<dt><a name="word25"><b>nfe-result</b>	( n1 nfe -- n2 n3 )</dt>
<dd>Get the match result of the n1th grouping, return match start n3 and end n2</dd>
</dl>
<h4>Inspection</h4>
<dl>
<dt><a name="word26"><b>nfe-dump</b>	( nfe -- )</dt>
<dd>Dump the expression</dd>
</dl>
<hr>
<div align="center">generated 24-Jul-2010 by <b>ofcfrth-0.10.0</b></div>
</body>
</html>
